'''  对每一种类型的对象的深拷贝，浅拷贝进行试验  '''
'''
浅拷贝：对可变类型的第一层对象进行拷贝，拷贝后的对象需要开辟一个新的内存空间存储该对象，子对象不会进行拷贝
深拷贝：只要发现该对象有可变类型就会对该对象最外层到最后一个可变类型的每一层进行拷贝，拷贝成功则开辟新的内存空间存储该对象，深拷贝拷贝多层对象
总结：无论深拷贝还是浅拷贝主要针对的是可变类型对象的拷贝，不可变类型拷贝对象没有意义，因为不可变类型对象不能在原有内存空间的基础上修改数据
'''

import copy

# 1.不可变类型
a1 = 1
a2 = 'a'
a3 = 'ddfg'
a4 = (1, 'w')
# 不可变里带可变类型
a5 = (1, (1, 2), (1, 2, [1, 2]), [2, 5], {'name': 'li'})

# 2.可变类型
a6 = [1, 2, 3]
a7 = [1, [2, 3], (1, [4, 5])]  # 可变里带不可变类型
a8 = {'name': 'li', 'age': 11}

b1 = copy.copy(a1)
b2 = copy.copy(a2)
b3 = copy.copy(a3)
b4 = copy.copy(a4)
b5 = copy.copy(a5)
b6 = copy.copy(a6)
b7 = copy.copy(a7)
b8 = copy.copy(a8)

bb1 = copy.deepcopy(a1)
bb2 = copy.deepcopy(a2)
bb3 = copy.deepcopy(a3)
bb4 = copy.deepcopy(a4)
bb5 = copy.deepcopy(a5)
bb6 = copy.deepcopy(a6)
bb7 = copy.deepcopy(a7)
bb8 = copy.deepcopy(a8)
# ==============================
# （1）最外层对象id
# print(id(a1), id(b1), id(bb1), '\n', id(a2), id(b2), id(bb2), '\n', id(a3), id(b3), id(bb3), '\n', id(a4), id(b4),
#       id(bb4), '\n', id(a5), id(b5), id(bb5), '\n', id(a6), id(b6), id(bb6), '\n', id(a7), id(b7), id(bb5), '\n',
#       id(a8), id(b8), id(bb8))
'''
 10853632 10853632 10853632                       三个id相同                               
 139623527805088 139623527805088 139623527805088  三个id相同
 139623527667784 139623527667784 139623527667784  三个id相同
 139623498353288 139623498353288 139623498353288  三个id相同
  
 139623528597376 139623528597376 139623498677504  深拷贝id变了
 
 139623498352072 139623498388488 139623498389640  id均不同
 139623498389064 139623498389128 139623498677504  id均不同
 139623528153352 139623498389256 139623498339016  id均不同
'''
# ==============================
# （2）最外层不可变，内部不可变
# a3 = 'ddfg'
print(id(a3[0]), id(b3[0]), id(bb3[0]))
'''140003616292064 140003616292064 140003616292064 #相同   '''
# ==============================
'''
# （3）最外层不可变，内部可变
# a5 = (1, (1,2), (1, 2,[1,2]), [2, 5], {'name': 'li'})、
'''
# print(id(a5[0]),id(b5[0]),id(bb5[0]))
# print(id(a5[1]),id(b5[1]),id(bb5[1]))
# print(id(a5[2]),id(b5[2]),id(bb5[2]))
# print(id(a5[3]),id(b5[3]),id(bb5[3]))
# print(id(a5[4]),id(b5[4]),id(bb5[4]))
'''

10853632 10853632 10853632
139923069719640 139923069719640 139923069719640
139923069749960 139923069749960 139923069749960
139923069781896 139923069781896 139923069781768
139923099549832 139923099549832 139923069759880'''

# ==============================
'''
（4）可变里有不可变，再有可变
a7 = [1, [2, 3],(1,[4,5])]  
a7[0]       可变=》不可变
a7[1]       可变=》可变
a7[1][0]    可变=》可变=》不可变
a7[2]       可变=》不可变
a7[2][1]    可变=》不可变 =》可变
a7[2][1][0] 可变=》不可变 =》可变=》不可变
'''

# print(id(a7[0]),id(b7[0]),id(bb7[0]))
# print(id(a7[1]),id(b7[1]),id(bb7[1]))
# print(id(a7[1][0]),id(b7[1][0]),id(bb7[1][0]))
# print(id(a7[2]),id(b7[2]),id(bb7[2]))
# print(id(a7[2][1]),id(b7[2][1]),id(bb7[2][1]))
# print(id(a7[2][1][0]),id(b7[2][1][0]),id(bb7[2][1][0]))
'''
10853632 10853632 10853632
140191748482824 140191748482824 140191748483080
10853664 10853664 10853664
140191748458632 140191748458632 140191748457864
140191748447944 140191748447944 140191748483336
10853728 10853728 10853728 '''
